<?php
/**
 * Created by PhpStorm.
 * User: Tioncico
 * Date: 2019/3/18 0018
 * Time: 9:40
 */

namespace App\HttpController;


use App\Model\Picture;

class Upload extends Base
{
    /**
     * 获取文件上传图片路径
     * @return Picture
     */
    public function getPictureModel()
    {
        return new Picture();
    }

    /**
     * 单个文件上传
     * @return bool
     * @throws \App\Common\Exception\ThrowException
     */
    function uploadPic()
    {
        $request = $this->request();
        $imgFile = $request->getUploadedFile('file');//获取一个上传文件,返回的是一个\EasySwoole\Http\Message\UploadFile的对象
        $pictureModel=$this->getPictureModel();
        //$pictureModel->setSaveUrl('http://www.baidu.com');
        return $this->writeJson('操作成功', $pictureModel->upload($imgFile));
    }
}